package com.kaiwukj.android.ufamily.mvp.ui.activity;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.app.base.BaseSwipeBackActivity;
import com.kaiwukj.android.ufamily.mvp.ui.widget.home.ShopWebView;
import com.qmuiteam.qmui.widget.QMUITopBar;

import butterknife.BindView;

import static com.kaiwukj.android.ufamily.app.constant.ARouterUrlKt.WebViewUrl;

@Route(path = WebViewUrl)
public class WebActivity extends BaseSwipeBackActivity {
    @BindView(R.id.qmui_web_view)
    ShopWebView mWebView;
    @BindView(R.id.qtb_web_view)
    QMUITopBar mTopBar;
    @Autowired(name = "EXTRA_KEY_WEB_URL")
    String url;
    @Autowired(name = "EXTRA_KEY_WEB_TITLE")
    String title;


    @Override
    protected int getLayoutId() {
        if (android.os.Build.VERSION.SDK_INT != Build.VERSION_CODES.O) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        ARouter.getInstance().inject(this);
        return R.layout.activity_web;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {

        mTopBar.setTitle(title);
        mTopBar.addLeftBackImageButton().setOnClickListener(view -> onBackPressedSupport());
        mWebView.loadUrl(url);
        //mWebView.loadUrl("file:///android_asset/index.html");
        mWebView.setOnShopListener(new ShopWebView.OnShopListener() {
            @Override
            public void onTokenInvalid() {

            }

            @Override
            public void onPayByAli(String json) {

            }

            @Override
            public void onPayByWechat(String json) {

            }

            @Override
            public void onGetPageTitle(String json) {

            }

            @Override
            public void onCallPhone(String json) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_DIAL);
                intent.setData(Uri.parse("tel://" + json));
                WebActivity.this.startActivity(intent);
            }

            @Override
            public void onGoHome() {

            }
        });

    }

    /**
     * 初始化数据
     *
     * @param savedInstanceState
     */
    @Override
    protected void initData(@Nullable Bundle savedInstanceState) {

    }

    @Override
    public void post(Runnable runnable) {

    }
}
